package com.aspose.cells;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;

class zci {
   protected static final byte[] a = new byte[]{65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47};
   protected static final byte[] b = new byte[256];

   public static byte[] a(String var0, String var1) throws UnsupportedEncodingException {
      return a(var0.getBytes(var1));
   }

   public static byte[] a(byte[] var0) {
      ByteArrayInputStream var1 = new ByteArrayInputStream(var0);
      int var3 = var0.length;
      int var2;
      if ((var2 = var3 % 4) != 0) {
         var3 += 4 - var2;
      }

      var3 = var3 * 3 / 4;
      ByteArrayOutputStream var4 = new ByteArrayOutputStream(var3);

      try {
         a(var1, var4, false);
      } catch (IOException var6) {
         throw new RuntimeException(var6);
      }

      return var4.toByteArray();
   }

   private static final int a(InputStream var0, boolean var1) throws IOException {
      int var3 = 0;

      byte var4;
      do {
         int var2 = var0.read();
         if (var2 == -1) {
            return -1;
         }

         var4 = b[(byte)var2];
         if (var1 && (var4 == -1 || var3 > 0 && var4 > -1)) {
            throw new IOException("Unexpected character");
         }

         if (var4 == -3) {
            ++var3;
         }
      } while(var4 <= -1);

      return var4;
   }

   public static void a(InputStream var0, OutputStream var1, boolean var2) throws IOException {
      int[] var3 = new int[4];
      boolean var4 = false;

      while(!var4 && (var3[0] = a(var0, var2)) != -1 && (var3[1] = a(var0, var2)) != -1) {
         var3[2] = a(var0, var2);
         var3[3] = a(var0, var2);
         var1.write(var3[0] << 2 | var3[1] >> 4);
         if (var3[2] != -1) {
            var1.write(var3[1] << 4 | var3[2] >> 2);
            if (var3[3] != -1) {
               var1.write(var3[2] << 6 | var3[3]);
            } else {
               var4 = true;
            }
         } else {
            var4 = true;
         }
      }

      var1.flush();
   }

   static {
      for(int var0 = 0; var0 < b.length; ++var0) {
         b[var0] = -1;
      }

      for(byte var1 = 0; var1 < a.length; b[a[var1]] = var1++) {
         ;
      }

      b[32] = -2;
      b[10] = -2;
      b[13] = -2;
      b[9] = -2;
      b[12] = -2;
      b[61] = -3;
   }
}
